/*
 * 描述 @version 1 
 * Create by cy on 2018/10/25
 * */
// $('.score').attr('backgroundPositionX',-16);
function request(page) {
    $.ajax({
        type: 'get',
        url: 'https://sclub.jd.com/comment/productPageComments.action?productId=7437788&score=0&sortType=5&page='+page+'&pageSize=10&isShadowSku=0&rid=0&fold=1',
        success: function (res) {
            console.log(res);
            //头部
            var productCommentSummary='<div class="comment-percent">\n' +
                '                <span>好评度</span>\n' +
                '                <p>'+res.productCommentSummary.goodRateShow+'<span>%</span></p>\n' +
                '            </div>\n' ;
            var  hotCommentTagStatistics= '<div class="percent-info">\n';
            res.hotCommentTagStatistics.forEach(function (t) {
                 hotCommentTagStatistics+= '<span class="tag-1">'+t.name+'('+t.count+')</span>\n';
            });
            hotCommentTagStatistics+= '            </div>';
            var commentInfo=productCommentSummary+hotCommentTagStatistics;
            $('#comment-info').html(commentInfo);

            //用户头部部分
            var count=' <li>全部评价('+res.productCommentSummary.commentCountStr+')</li>\n' +
                '                    <li>晒图('+res.productCommentSummary.showCountStr+')</li>\n' +
                '                    <li>视屏晒单('+res.productCommentSummary.videoCountStr+')</li>\n' +
                '                    <li>追评('+res.productCommentSummary.afterCountStr+')</li>\n' +
                '                    <li>好评('+res.productCommentSummary.goodCountStr+')</li>\n' +
                '                    <li>中评('+res.productCommentSummary.generalCountStr+')</li>\n' +
                '                    <li>差评('+res.productCommentSummary.poorCountStr+')</li>';
            $('#user-ul').html(count);

            //用户评论
            $('.user-content').remove();
            res.comments.forEach(function (t) {
                $('.star').css('backgroundPositionX',-16*(5-t.score));
                var userImageUrl=t.userImageUrl.indexOf('http')!=-1?t.userImageUrl:('https://'+t.userImageUrl);
                var avatar= '<div class="user-content">\n' +
                    '<div class="avatar">\n' +
                '                    <div class="user-level">\n' +
                '                        <img src="'+userImageUrl+'" alt="">\n' +
                '                        <span> '+t.nickname+'</span>\n' +
                '                    </div>\n' ;
                if(t.userLevelName=='PLUS会员'){
                    avatar+=
                    '                    <div class="plus">\n' +
                    '                        PLUS会员\n' +
                    '                    </div>\n' ;
                }
                avatar+=
                '                </div>\n' +
                '                <div class="container">\n' +
                '                    <p class="star"></p>\n' +
                '                    <p class="con">'+t.content+'</p>\n' +
                '                    <p class="pic-list">\n' ;
                    if(t.images){
                        t.images.forEach(function (item) {
                            var imgUrl=item.imgUrl.indexOf('http')!=-1?item.imgUrl:('http://'+item.imgUrl);
                            avatar+=
                            '                        <img src="'+imgUrl+'" alt="">\n' ;
                        })
                    }
                    if(t.videos){
                        t.videos.forEach(function (t2) {
                            avatar+=' <p class="video">\n' +
                                '                        <video src="'+t2.remark+'" muted autoplay loop></video>\n' +
                                '                    </p>'
                        })
                    }
                    avatar+=
                    '<p>\n' +
                    '                        <div class="order-info">\n' +
                    '                            <span>'+t.productColor+'</span>\n' +
                    '                            <span>'+t.productSize+'</span>\n' +
                    // '                            <span>256GB</span>\n' +
                    '                            <span>'+t.referenceTime+'</span>\n' +
                    '                        </div>\n' +
                    '                    </p>';
                    avatar+=
                '                    </p>\n' +
                '                </div>'+
                '                </div>';

                $('#user-info').append(avatar);

            });
        },
        dataType:'jsonp'
    })
}

$('#paging').paging({
    initPageNo:1,
    totalPages:21,
    totalCount:21,
    slideSpeed:2,
    jump:true,
    callback:function (page) {
        request(page);
    }
});